package com.recipe.controller;


import com.alibaba.fastjson.JSON;
import com.recipe.common.entity.Result;
import com.recipe.entity.Dish;
import com.recipe.entity.DishCollect;
import com.recipe.entity.vo.DishVo;
import com.recipe.service.DishCollectService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (DishCollect)表控制层
 *
 * @author lzk
 * @since 2024-06-18 13:53:50
 */
@RestController
@RequestMapping("dishCollect")
@Slf4j
@RequiredArgsConstructor
public class DishCollectController {
    private final DishCollectService dishCollectService;
    @PostMapping("/add")
    public Result<Boolean> add(@RequestBody DishCollect dishCollect) {
        if (log.isInfoEnabled()) {
            log.info("DishCollectController.add:{}", JSON.toJSONString(dishCollect));
        }

        dishCollectService.add(dishCollect);
        return Result.ok();
    }
    @PostMapping("/deleteById")
    public Result<Boolean> deleteById(@RequestBody DishVo dishVo) {
        if (log.isInfoEnabled()) {
            log.info("DishCollectController.delete:{}", dishVo);
        }

        dishCollectService.deleteById(dishVo);
        return Result.ok();
    }

    @GetMapping("/getCollectCount/{dishId}")
    public Result<Integer> getCollectCount(@PathVariable Long dishId) {
        if (log.isInfoEnabled()) {
            log.info("DishCollectController.getCollectCount:{}", dishId);
        }

        Integer count = dishCollectService.getCollectCount(dishId);
        return Result.ok(count);
    }
    @GetMapping("/getMyCollect")
    public Result<List<Dish>> getMyCollect(@RequestParam String username){
        return Result.ok(dishCollectService.getMyCollect(username));
    }
    @GetMapping("/isCollected/{dishId}/{userId}")
    public Result<Boolean> isCollected(@PathVariable String dishId, @PathVariable String userId) {
        if (log.isInfoEnabled()) {
            log.info("DishCollectController.isLiked:{},{}", dishId, userId);
        }

        Boolean isLiked = dishCollectService.isCollected(dishId, userId);
        return Result.ok(isLiked);
    }
}

